﻿
#include "../src/threadpool.h"
#include<iostream>
#include<thread>

using namespace std;
using namespace CWJ;

using ULL = unsigned long long;
void runTask(ULL st,ULL ed){
    ULL res = 0;
    for(int i=st;i<ed;i++)  res += i;
    std::cout << "Thread id= " <<std::this_thread::get_id() << " doTask --> res = "<< res << std::endl;
}

ULL runTaskHasRes(ULL st,ULL ed){
    ULL res = 0;
    for(int i=st;i<ed;i++)  res += i;
    return res;
}


int main() {
    CWJ::ThreadPool tp ;
    tp.start();
    std::cout<<" start submit "<<std::endl;
    vector<std::shared_ptr<Result<ULL>>> res_list;
    for(int i=0;i<100;i++) {
        tp.submitTask_(runTask, 1, 1e6);
        res_list.push_back((tp.submitTask_(runTaskHasRes,1,1e6)));
    }
    std::cout<<" end submit "<<std::endl;


    // Result<ULL>在调用get函数后， 会阻塞直到对应的任务被完成
    ULL res = 0;
    for(const auto& a : res_list){
        res += a->get();
    }

    std::cout<<"main: res:"<<res<<endl;

}



